﻿@using Pear.Web.Core
@inherits PearRazorPage<object>
@{ Layout = "~/Views/Shared/_Layout.cshtml"; }
@{ ViewData["Title"] = "字典类型新增";}
@section header
{

}
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">类型名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" lay-verify="name" autocomplete="off" placeholder="请输入类型名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-block">
                        <input type="text" name="sequence" lay-verify="sequence" autocomplete="off" placeholder="请输入排序号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="enabled"  value="true" lay-skin="switch" lay-text="启用|禁用" lay-filter="enabled" checked />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea type="text" name="remark" lay-verify="remark" autocomplete="off" placeholder="请输入备注" class="layui-input layui-textarea"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
@section footer
{
    <script>
        layui.use(['form', 'jquery', 'http', 'popup'], function () {
            let form = layui.form;
            let $ = layui.jquery;
            let http = layui.http;

            

            form.on('submit(user-save)', function (data) {

                if (data.field.enabled == "true") {
                    data.field.enabled = true;
                } else {
                    data.field.enabled = false;
                }

                http.post('/api/sysdata/add', JSON.stringify(data.field)).then((result) => {
                    if (result.succeeded) {
                        layer.msg("保存成功", { icon: 1, time: 1000 }, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("dict-type-table");
                        });
                    } else {
                        layer.msg("保存失败", { icon: 2, time: 1000 });
                    }
                });
                return false;
            });
        })
    </script>
}